package upicgame.interceptors;

import org.springframework.web.servlet.HandlerInterceptor;
import upicgame.entity.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @program: upicgame
 * @description: 登录拦截器
 * @author: lhq
 * @create: 2019-12-26 18:01
 */
public class LoginInterceptor implements HandlerInterceptor {
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		System.out.println("????");
		String uri = request.getRequestURI();
		System.out.println(uri);
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("user");
		System.out.println(user);
		if(uri.contains("/login")){
			return true;
		}
		if ("/upicgame/verifyCode".equals(uri)){
			return true;
		}
		if ("/upicgame/game_detail".equals(uri)){
			return true;
		}
		if (user != null){
			return true;
		} else {
			response.sendRedirect("index.jsp");
		}
		return false;
	}
}
